package com.just.springbootmybatis.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.just.springbootmybatis.model.User;
import com.just.springbootmybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public int createUser(@RequestBody User user) {
        return userService.addUser(user);
    }

    /**
     * 返回不带分页信息的
     */
    @GetMapping("/list")
    public List<User> findAllUser(int page, int size) {
        return userService.findAllUser(page, size);
    }

    /**
     * 返回带分页信息的
     */
    @GetMapping("/list2")
    public Object findAllUser2(int page, int size) {
        Page<User> users = userService.findAllUser2(page, size);
        PageInfo<User> pageInfo = new PageInfo<>(users);
        return pageInfo;
    }
}
